<template>
    <div class="equipment-clear"
         style="height: 100%;">
        <vue-better-scroll class="wrapper"
                           ref="scroll"
                           :scrollbar="scrollbarObj"
                           :pullDownRefresh="pullDownRefreshObj"
                           :pullUpLoad="pullUpLoadObj"
                           :startY="parseInt(startY)"
                           @pullingUp="onPullingUp">
            <ul class="nav">
                <li :class="{'active':navIndex === 0}"
                    @click="navIndex = 0;getData()">
                    <p>拆除前检查</p>
                </li>
                <li :class="{'active':navIndex === 1}"
                    @click="navIndex = 1;getData()">
                    <p>拆除旁站</p>
                </li>
            </ul>
            <div v-show="navIndex === 0">
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>单位名称</label>
                    </div>
                    <div class="equipment-right-select"
                         @click="selectType">
                        <span>{{checkcompany0.Name?checkcompany0.Name:'请选择'}}</span>
                        <i class="iconfont icon-jinru rightmsg"></i>
                    </div>
                </div>
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>设备类型</label>
                    </div>
                    <group>
                        <popup-picker :data="equipmentType"
                                      placeholder='默认全部'
                                      v-model="equipmentTypeVal0"></popup-picker>
                    </group>
                </div>
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>开始时间</label>
                    </div>
                    <group>
                        <datetime v-model="startTime0"></datetime>
                    </group>
                </div>
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>结束时间</label>
                    </div>
                    <group>
                        <datetime v-model="endTime0"></datetime>
                    </group>
                </div>
                <div class="btns">
                    <!-- <button>保存</button> -->
                    <button class="green width200"
                            @click="getData">查询</button>
                </div>
                <h3>总数：{{listAllCount0}}</h3>
                <ul class="lists">
                    <li v-for="(item,index) in lists0"
                        :key="index">
                        <router-link :to="{path:'/equipmentClearBefore',query:{id:item.ID}}">
                            <div>
                                <h5>{{item.EquipmentName}}</h5>
                                <p>拆除日期：{{item.CheckDate}}</p>
                                <p>{{item.ProjectName}}</p>
                            </div>
                            <div class="status">
                                <span :class="[item.IsSubmit=='已提交' ? 'blue' : 'orange']">【{{item.IsSubmit}}】</span>
                                <x-icon type="ios-arrow-right"
                                        size="20"
                                        class="icon-right"></x-icon>
                            </div>
                        </router-link>
                    </li>
                </ul>
            </div>
            <div v-show="navIndex === 1">
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>单位名称</label>
                    </div>
                    <div class="equipment-right-select"
                         @click="selectType">
                        <span>{{checkcompany0.Name?checkcompany0.Name:'请选择'}}</span>
                        <i class="iconfont icon-jinru rightmsg"></i>
                    </div>
                </div>
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>设备类型</label>
                    </div>
                    <group>
                        <popup-picker :data="equipmentType"
                                      placeholder='默认全部'
                                      v-model="equipmentTypeVal1"></popup-picker>
                    </group>
                </div>
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>开始时间</label>
                    </div>
                    <group>
                        <datetime v-model="startTime1"></datetime>
                    </group>
                </div>
                <div class="form-item form-item-style1">
                    <div class="label-title">
                        <label>结束时间</label>
                    </div>
                    <group>
                        <datetime v-model="endTime1"></datetime>
                    </group>
                </div>
                <div class="btns">
                    <!-- <button>保存</button> -->
                    <button class="green width200"
                            @click="getData">查询</button>
                </div>
                <h3>总数：{{listAllCount1}}</h3>
                <ul class="lists">
                    <li v-for="(item,index) in lists1"
                        :key="index">
                        <router-link :to="{path:'/equipmentSide',query:{id:item.ID}}">
                            <div>
                                <h5>{{item.EquipmentName}}</h5>
                                <p>验收日期：{{item.DismantleDate}}</p>
                                <p>{{item.ProjectName}}</p>
                            </div>
                            <div class="status">
                                <span :class="[item.IsSubmit=='已提交' ? 'blue' : 'orange']">【{{item.IsSubmit}}】</span>
                                <x-icon type="ios-arrow-right"
                                        size="20"
                                        class="icon-right"></x-icon>
                            </div>
                        </router-link>
                    </li>
                </ul>
            </div>
        </vue-better-scroll>
        <myMenu></myMenu>
        <companyProp :companyPropShow="companyPropShow"
                     :selectCompany="selectCompany"></companyProp>
    </div>
</template>
<script>
import VueBetterScroll from 'vue2-better-scroll'
import formatDate from '@/utils/formatDate'
import myMenu from '@/commonComponents/menu'
import companyProp from '@/commonComponents/companyProp'
export default {
    name: 'equipmentClearManage',
    data () {
        return {
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: false,
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            navIndex: 0,
            startTime0: `${formatDate().split('-')[0]}-${formatDate().split('-')[1]}-01`,
            endTime0: formatDate(),
            startTime1: `${formatDate().split('-')[0]}-${formatDate().split('-')[1]}-01`,
            endTime1: formatDate(),
            userInfo: '',
            equipmentTypeData: '',
            equipmentType: [[]], //  设备类型
            equipmentTypeVal0: ['全部'], // 选中设备类型
            equipmentTypeVal1: ['全部'],
            checkcompany0: {
            }, //  单位名称
            checkcompany1: {
            }, //  单位名称
            lists0: [],
            lists1: [],
            pageIndex0: 0, // 当前页
            listAllCount0: 0, // 总条数
            pageIndex1: 0, // 当前页
            listAllCount1: 0, // 总条数
            companyPropShow: false
        }
    },
    components: {
        VueBetterScroll,
        myMenu,
        companyProp
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this[`checkcompany${this.navIndex}`] = {
            Name: this.userInfo.deptname,
            Id: this.userInfo.deptid
        }
        this.getEquipment()
        if (this.navIndex == 0) {
            this.handleSubmit0()
        } else {
            this.handleSubmit1()
        }
    },
    methods: {
        selectType () {
            // this.$router.push({ path: '/testing/lookcompany' })
            this.companyPropShow = true
        },
        onButtonClick (type) {
            alert('on button click ' + type)
        },
        handleEvents (type) {
            console.log('event: ', type)
        },
        getEquipment () { // 获取设备类型
            let params = {
                'allowPaging': false,
                'business': 'GetEquipment',
                'data': {},
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.equipmentTypeData = res.data.data
                    this.equipmentType[0].push('全部')
                    this.equipmentTypeData.forEach((item) => {
                        this.equipmentType[0].push(item.EquipmentTypeName)
                    })
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        },
        handleSubmit0 () {
            this.$vux.loading.show({
                text: '加载中...'
            })
            let params = {
                'allowPaging': false,
                'business': 'EquipmentDismantlingCheckList',
                'data': {
                    ProjectID: this.userInfo.deptid,
                    Start: this.startTime0,
                    End: this.endTime0,
                    EquipmentTypeNo: ''
                },
                'pageIndex': this.pageIndex0,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            for (let i = 0; i < this.equipmentTypeData.length; i++) {
                if (this.equipmentTypeVal0[0] == this.equipmentTypeData[i].EquipmentTypeName) {
                    params.data.EquipmentTypeNo = this.equipmentTypeData[i].EquipmentTypeNo
                    break
                }
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.listAllCount0 = res.data.count
                    this.lists0 = this.lists0.concat(res.data.data)
                    if (this.lists0.length < this.listAllCount0) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        },
        handleSubmit1 () {
            this.$vux.loading.show({
                text: '加载中...'
            })
            let params = {
                'allowPaging': false,
                'business': 'GetDismantlingStationList',
                'data': {
                    ProjectID: this.userInfo.deptid,
                    Start: this.startTime1,
                    End: this.endTime1,
                    EquipmentTypeNo: ''
                },
                'pageIndex': this.pageIndex1,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            for (let i = 0; i < this.equipmentTypeData.length; i++) {
                if (this.equipmentTypeVal1[0] == this.equipmentTypeData[i].EquipmentTypeName) {
                    params.data.EquipmentTypeNo = this.equipmentTypeData[i].EquipmentTypeNo
                    break
                }
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.listAllCount1 = res.data.count
                    this.lists1 = this.lists1.concat(res.data.data)
                    if (this.lists1.length < this.listAllCount1) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        },
        onPullingUp () {
            this[`pageIndex${this.navIndex}`]++
            this[`handleSubmit${this.navIndex}`]()
        },
        getData () {
            this[`pageIndex${this.navIndex}`] = 0
            this[`lists${this.navIndex}`] = []
            this[`handleSubmit${this.navIndex}`]()
        },
        selectCompany (item) {
            this.companyPropShow = false
            this[`checkcompany${this.navIndex}`] = {
                Name: item.Name,
                Id: item.Id
            }
        }
    }
}
</script>
<style lang="less" scoped>
.nav {
    display: flex;
    padding-bottom: 10px;
    background: #ebeef3;
    li {
        display: flex;
        justify-content: center;
        flex: 1;
        background: #fff;
        &.active p {
            color: #2269ff;
            border-bottom: 4px solid #2269ff;
        }
    }
    p {
        height: 60px;
        line-height: 60px;
        text-align: center;
        font-size: 18px;
        color: #999;
    }
}
h3 {
    height: 40px;
    line-height: 40px;
    color: #999;
    font-size: 14px;
    background: #ebeef2;
    padding-right: 20px;
    text-align: right;
}
.lists {
    padding-left: 20px;
    a {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 14px 20px 14px 0;
        border-bottom: 1px solid #efeff4;
    }
    h5 {
        line-height: 18px;
        color: #333;
        font-size: 13px;
        font-weight: 700;
    }
    p {
        font-size: 13px;
        color: #666;
        line-height: 18px;
    }
    .status {
        display: flex;
        align-items: center;
        span {
            font-size: 12px;
        }
        .orange {
            color: #fe7234;
        }
        .blue {
            color: #2369ff;
        }
    }
}
</style>
